﻿<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>创建排故单（新）</title>
    <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
    <style>
        .easyui-linkbutton{margin-left:20px;}
        table tr td{padding:0px 5px}
       #fm .l-btn-text{margin-top:3px}
    </style>
</head>
<body>
 <div class="panelSection">    
        <div class="easyui-panel " title="查询区域" style="padding:3px;" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
           <form id="searchForm" method="post">
	    	<table>
	    		<tr class="divLabel">
                    <td>发动机号:</td>
                    <td>订单号:</td>
                    <td>订单状态:</td>
	    		</tr>
	    		<tr>
	    			<td><input  name="Machine" class="easyui-textbox" style="width: 120px; height: 22px" /></td>
	    			<td><input  name="MfgOrderName" class="easyui-textbox" style="width: 120px; height: 22px" /></td>
                    <td><input  name="Status" class="easyui-textbox" style="width: 120px; height: 22px" id="ddlStatus"/></td>
                    <td><a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.searchData()">查询</a></td>
	    			<td><a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.searchReset()">重置</a></td>
	    		</tr>
	    	</table>
	    </form>
        </div> 
    </div>
    <div class="panelSection">
         <div class="easyui-panel " title="结果区域" style="padding:3px;" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
         <div style="float:left;width:800px;">
            <table id="mfgOrder" style="height:340px" data-options="rownumbers:true"></table>
            <div id="pp" style="float: right" class="easyui-pagination" data-options="   
                 layout:['first','prev','next','last','manual','info'],              
                    total: 0,
                    showPageList: false,
                    showPageInfo: false,
                    showRefresh: false,
                    afterPageText:'共&nbsp{pages}&nbsp页',
                     buttons:[{
                            iconCls:'',
                            text:'Go',
                            id:'pageGo'
                    }]
                ">
                    </div>
            </div> 
            <table id="DealFaultBill" style="height:340px;float:left;" data-options="rownumbers:true"></table>
        </div>
    </div>
    <div style="margin-top:10px;">
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.createDealFaultBill()">开具排故单</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.deleteDealFaultBill()">删除</a>
         <form id="fm" method="post" enctype="multipart/form-data" style="display:inline-block;margin-left:20px;">
             <input class="easyui-filebox" id="fileUpload" name="fileUpload" style="width:69px;height: 24px;line-height: 24px;" data-options="buttonText:'添加附页',onChange:function(){page.easyuiUpload(this);}"/>
             </form>
    </div>
     <!--信息提示区域-->
    <div id="statusMessage" style="font-size: 14px; height: 40px"></div>
</body>
</html>
<script src="/InSiteWebApplication/Scripts/json2.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script type="text/javascript">
    //创建人：longb
    //日期：2023-06-25
    //描述：排故单附页查看
    var page = {
        pagetotal: 0,
        pageSize: 20,
        pageNumber: 1,
        rootPath: getRootPath(), //网站根路径
        ajaxUrl: getRootPath() + "/Ashx/ZsHandler/ZSDealFaultBillHandler.ashx",
        //初始化页面
        init: function () {
            page.bind();
            page.initCombox();
            customizedEasyuiPagination('pp'); //定制化分页
        },
        initCombox:function(){
            $('#ddlStatus').combobox({
                data:[{id:'全部',text:'全部'},{id:'未分解',text:'未分解'},{id:'已分解',text:'已分解'},{id:'已入库',text:'已入库'}],
                valueField:'id',
                textField:'text',
                panelHeight:'auto',
                value:'全部'
            });
        },
        //页面事件绑定
        bind: function () {
            $('#mfgOrder').datagrid({
                checkOnSelect: true,
                selectOnCheck: false,
                singleSelect: true,
                rownumbers: true,
                columns: [[
                 { field: 'MFGORDERNAME', title: '订单号', width: 150 },
                 { field: 'ORDERTYPENAME', title: '类型', width: 70 },
		         { field: 'ATTRIBUTEVALUE', title: '发动机号', width: 100 },
                 { field: 'PRODUCTNAME', title: '物料号', width: 120 },
                 { field: 'DESCRIPTION', title: '物料描述', width: 120 },
                 { field: 'PRODUCTFAMILYNAME', title: '机型', width: 50 },
                 { field: 'STATUS', title: '状态', width: 70 },
                 { field: 'DFCOUNT', title: '单据数', width: 50 }
                ]],
                onSelect:function(index,row){
                    page.getDealFaultBillData(row);
                },
                onLoadSuccess: function (data) {
                    $('#pp').pagination('refresh', {	// 改变选项，并刷新分页栏信息
                        total: page.pagetotal,
                        pageSize: page.pageSize,
                        pageNumber: page.pageNumber
                    });
                    customizedEasyuiPagination('pp'); //定制化分页
                },
            });
            //分页事件
            $('#pp').pagination({
                onSelectPage: function (pageNumber, pageSize) {
                    customizedEasyuiPagination('pp'); //定制化分页
                    page.pageSize = pageSize; page.pageNumber = pageNumber;
                    page.getOrderData(null);
                }
            });
            //绑定分页go按钮
            $('#pageGo').on("click", function () {
                var pageNumber = $(this).parents('tr').find('.pagination-num').val();
                page.pageNumber = pageNumber;
                page.getOrderData(null);
            });

            $('#DealFaultBill').datagrid({
                checkOnSelect: true,
                selectOnCheck: false,
                singleSelect: true,
                rownumbers: true,
                columns: [[
                 { field: 'DEALFAULTBILLNAME', title: '单号', width: 200 },
                 { field: 'PRODUCTNAME', title: '零组件号', width: 100 },
		         { field: 'PRODUCTBATCHNO', title: '批次', width: 120 },
                 { field: 'STATUS', title: '状态', width: 100 },
                ]]
            });
        },
        //查询
        searchData: function () {
            clearMessage();
            page.pageNumber = 1;
            page.getOrderData(null);
        },
        //查询重置
        searchReset: function () {
            $('#searchForm').form('clear');
            page.initCombox();
            clearMessage();
        },
        getOrderData:function(index){
            $('#DealFaultBill').datagrid('loadData',[]);
            var frdata = $('#searchForm').serializeArray();
            var data = {};
            $.each(frdata, function () {
                data[this.name] = this.value
            });
            var param = {
                action: "GetOrderData",
                pageSize: page.pageSize,
                pageNumber: page.pageNumber,
                data: JSON.stringify(data)
            };
            page.post(param, function (res) {
                if (res.Result) {
                    page.pagetotal = res.RowCount;
                    $('#mfgOrder').datagrid('loadData', res.DBTable);
                    if(index!=null){$('#mfgOrder').datagrid('selectRow',index);}
                }
            });
        },
        //查询排故单信息
        getDealFaultBillData: function (row) {
         $('#DealFaultBill').datagrid('loadData',[]);
            var param = {
                action: "GetDealFaultBillData",
                mfgid: row.MFGORDERID
            };
            page.post(param, function (res) {
                $('#DealFaultBill').datagrid('loadData', res);
            });
        },
        createDealFaultBill:function(){
            var mrow= $('#mfgOrder').datagrid('getSelected');
            var drow= $('#DealFaultBill').datagrid('getSelected');
            var data={};
            if(mrow==null){displayMessage('没有选择订单',false);return;}
            data.mfgorderid=mrow.MFGORDERID;
            data.machine=mrow.ATTRIBUTEVALUE;
            data.productfamilyname=mrow.PRODUCTFAMILYNAME;
            if(drow!=null){
                if(Number(drow.TRANSFERSTATUS)>1){displayMessage('已经确认不可更改',false);return;}else{
                    data.PGD=drow.DEALFAULTBILLNAME;
                }
            }
            page.post({action:'CreateDealFaultBill', data: JSON.stringify(data)}, function (res) {
                if(res.Result){
                    var someValue = window.showModalDialog("DealFaultCreatePopupForm.aspx?_Type=0", "", "dialogWidth:900px; dialogHeight:550px; status=no; center: Yes; resizable: NO;");
                    page.getOrderData($('#mfgOrder').datagrid('getRowIndex',mrow));
                }
            });
        },
        deleteDealFaultBill:function(){
            var mrow= $('#mfgOrder').datagrid('getSelected');
            var row= $('#DealFaultBill').datagrid('getSelected');
            if(row==null){displayMessage('请选择一条排故单记录再进行操作',false);return;}
            if(Number(row.TRANSFERSTATUS)>2){displayMessage('已经返出不可删除',false);return;}
            page.post({action:'DeleteDealFaultBill',dfname:row.DEALFAULTBILLNAME}, function (res) {
                if(res.Result){
                   page.getOrderData($('#mfgOrder').datagrid('getRowIndex',mrow));
                }
                displayMessage(res.Message, res.Result);
            });
        },
        easyuiUpload: function (obj) {
            var row= $('#DealFaultBill').datagrid('getSelected');
            if(row==null){displayMessage('请选择一条排故单记录再进行操作',false);return;}
            var dealFaultBillNAME=row.DEALFAULTBILLNAME;
            if ($('#fileUpload').filebox('getValue') != "") {
                clearMessage();
                $('#fm').form('submit', {
                    url: page.ajaxUrl + "?action=ImportDealFaultBillSheet&dealFaultBillNAME=" + dealFaultBillNAME,
                    onSubmit: function () {
                        return $(this).form('validate');
                    },
                    success: function (result) {
                        $('#fileUpload').filebox('clear');
                        var res = JSON.parse(result); 
                        displayMessage(res.Message, res.Result);
                    }
                });
            }
        },
        //post数据
        post: function (param, callback) {
            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                data: param,
                cashe: false,
                async: true,
                dataType: "json",
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    callback(data);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    displayMessage(XMLHttpRequest.responseText, false);
                }
            });
        }
    }
    $(function () {
        page.init();
    });
</script>
